<template>
  <div class="app-container">
    <el-container class="main-container">
      <!-- 侧边栏 -->
      <el-aside width="240px" class="sidebar">
        <div class="logo">
          <h1>Chrome Manager</h1>
        </div>
        <el-menu
          :default-active="activeMenu"
          class="sidebar-menu"
          router
        >
          <el-menu-item index="/window-manager">
            <el-icon><i-ep-monitor /></el-icon>
            <span>窗口管理</span>
          </el-menu-item>
          <el-menu-item index="/environment">
            <el-icon><i-ep-document-copy /></el-icon>
            <span>环境创建</span>
          </el-menu-item>
          <el-menu-item index="/layout">
            <el-icon><i-ep-s-grid /></el-icon>
            <span>布局管理</span>
          </el-menu-item>
          <el-menu-item index="/sync">
            <el-icon><i-ep-timer /></el-icon>
            <span>同步控制</span>
          </el-menu-item>
          <el-menu-item index="/batch-actions">
            <el-icon><i-ep-operation /></el-icon>
            <span>批量操作</span>
          </el-menu-item>
          <el-menu-item index="/settings">
            <el-icon><i-ep-setting /></el-icon>
            <span>设置</span>
          </el-menu-item>
        </el-menu>
      </el-aside>

      <!-- 主内容区 -->
      <el-container class="content-container">
        <el-header height="60px" class="app-header">
          <div class="header-content">
            <h2>{{ pageTitle }}</h2>
            <div class="header-actions">
              <el-button type="text" @click="refreshData">
                <el-icon><i-ep-refresh /></el-icon>
              </el-button>
              <el-dropdown>
                <el-button type="text">
                  <el-icon><i-ep-more /></el-icon>
                </el-button>
                <template #dropdown>
                  <el-dropdown-menu>
                    <el-dropdown-item>关于</el-dropdown-item>
                    <el-dropdown-item>帮助</el-dropdown-item>
                  </el-dropdown-menu>
                </template>
              </el-dropdown>
            </div>
          </div>
        </el-header>

        <el-main class="main-content">
          <router-view />
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script setup lang="ts">
import { computed, ref } from 'vue'
import { useRoute } from 'vue-router'
import {
  DocumentCopy,
  Grid,
  Monitor,
  More,
  Operation,
  Refresh,
  Setting,
  Timer
} from '@element-plus/icons-vue'

// 使用别名以避免命名冲突
const iEpMonitor = Monitor
const iEpDocumentCopy = DocumentCopy
const iEpSGrid = Grid
const iEpSync = Timer // 用Timer替代Sync图标
const iEpOperation = Operation
const iEpSetting = Setting
const iEpRefresh = Refresh
const iEpMore = More

const route = useRoute()

// 计算当前激活的菜单
const activeMenu = computed(() => route.path)

// 计算页面标题
const pageTitle = computed(() => {
  const titles: Record<string, string> = {
    '/window-manager': '窗口管理',
    '/environment': '环境创建',
    '/layout': '布局管理',
    '/sync': '同步控制',
    '/batch-actions': '批量操作',
    '/settings': '设置'
  }
  return titles[route.path] || 'Chrome Manager'
})

// 刷新数据
const refreshData = () => {
  // 触发路由组件的刷新逻辑
  window.location.reload()
}
</script>

<style lang="scss" scoped>
.app-container {
  height: 100vh;
  overflow: hidden;
}

.main-container {
  height: 100%;
}

.sidebar {
  background-color: #001529;
  height: 100%;
  overflow-y: auto;

  .logo {
    padding: 20px;
    text-align: center;
    border-bottom: 1px solid #1f1f1f;

    h1 {
      color: #fff;
      font-size: 18px;
      font-weight: 600;
    }
  }

  .sidebar-menu {
    height: calc(100% - 60px);
    background-color: #001529;

    &:deep(.el-menu-item) {
      color: rgba(255, 255, 255, 0.65);
      height: 50px;
      line-height: 50px;

      &:hover {
        background-color: #1890ff;
        color: #fff;
      }

      &.is-active {
        background-color: #1890ff;
        color: #fff;
      }

      .el-icon {
        margin-right: 10px;
      }
    }
  }
}

.content-container {
  height: 100%;
  background-color: #f5f7fa;
}

.app-header {
  background-color: #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  padding: 0 20px;
  height: 60px;

  .header-content {
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;

    h2 {
      font-size: 18px;
      font-weight: 500;
      color: #2c3e50;
      margin: 0;
    }

    .header-actions {
      display: flex;
      align-items: center;
      gap: 10px;
    }
  }
}

.main-content {
  padding: 20px;
  overflow-y: auto;
  height: calc(100% - 60px);
}
</style>